<template>
  <div o-Container>
    <o-list v-bind:source="list.building" v-bind="{created:create,modified:modify,exported:output}"/>
    <o-dialog v-bind:source="panel.build" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.building" v-bind="{saved:saveBuilding,backed:backBuilding}"></o-item>
        <o-list v-bind:source="list.floor" v-bind="{created:createFloor,modified:modifyFloor}"
                v-show="item.building.data.value!=null"/>
      </template>
    </o-dialog>
    <o-dialog v-bind:source="panel.floor" v-bind="{opened:load,closed:load}">
      <template slot="content">
        <o-item v-bind:source="item.floor" v-bind="{saved:saveFloor,loaded:loadFloor,backed:backFloor}"></o-item>
      </template>
    </o-dialog>
  </div>
</template>
<script>
  export default {
    name: "mms_cus_building_list", /* 这个name暂时不知道用啥用，根据官方文档说的是方便排错的 */
    data() {
      return {
        octopus: this.$parent.octopus,
        bulidingID: "",
        list: {
          building: {
            data: {
              id: 474, // 菜单表的八爪鱼ID
              cellData: [
                {name: "CompanyID", width: 140},//小区
                {name: "ProjectID", width: 200, filterKey: "=", link: [{binding: "CompanyID", mapping: "CompanyID"}]},//小区
                {name: "AreaID", width: 270, link: [{binding: "ProjectID", mapping: "ProjectID"}]},
                {name: "Name", width: 170, searchKey: "LIKE"},//名称
                {name: "NickName", width: 100},//别称
                {name: "Code", width: 100, searchKey: "LIKE"},//编号
                {name: "UniqueCode", width: 270, searchKey: "LIKE"},//编号
                {name: "TotalArea"},//总面积
                {name: "Address", width: 200},//地址
                // {name: "Introduction", width: 200},//备注
                {name: "Lng", width: 100},//别称
                {name: "Lat", width: 100},//别称
                {name: "CreateTime", width: 160, searchKey: "BETWEEN"},//创建时间
              ]
            }
          },
          floor: {
            data: {
              id: 83, // 菜单表的八爪鱼ID
              cellData: [
                {name: "BuildingID"},         // 所属楼宇
                {name: "Name"},               // 名称
                {name: "Code"},	// 区域名
                {name: "UniqueCode", width: 270},	// 区域名
                {name: "FloorArea"},          // 楼层面积
                {name: "FloorIndex"},         // 楼层索引
                {name: "Length", width: 80},  // 长度
                {name: "Width", width: 80},   // 宽度
                {name: "Height", width: 80},  // 层度
                {name: "Bearing"},            // 承重
                {name: "CreateTime", width: 160},//创建时间
              ],
              height: "200px"
            }
          },
        },
        item: {
          building: {
            data: {
              id: 2,
              value: "",
              cellData: [
                {name: "ProjectID"},// 项目
                {name: "AreaID", link: [{binding: "ProjectID", mapping: "ProjectID"}]},// 所属区域
                {name: "Name"},//名称
                {name: "NickName"},//别称
                {name: "Code"},//编解码
                {name: "TotalArea"},//总面积
                {name: "Lng"},//
                {name: "Lat"},//
                {name: "CreateTime"},//创建时间
                {name: "Address"},
                {name: "PhotoPath"},//照片
                {name: "SmallPhotoPath"},//缩照片
                {name: "Introduction"},//简介
              ],
            },
          },
          floor: {
            data: {
              id: 83,
              value: "",
              cellData: [
                {name: "BuildingID"},//站点
                {name: "Name"},//名称
                {name: "FloorArea"},//楼层面积
                {name: "FloorIndex"},//楼层索引
                {name: "Length", width: 80},  // 层长
                {name: "Bearing"},            // 承重
                {name: "Width", width: 80},   // 层宽
                {name: "Height", width: 80},  // 层高
                {name: "CreateTime", width: 160},//创建时间
                {name: "FloorPlanData"},//楼层数据
              ]
            },
          },
        },
        panel: {
          build: {
            visible: false,
          },
          floor: {
            visible: false,
          },
          budget: {
            visible: false,
          },
        },
      }
    },
    created: function () {
      // this.init();
    },
    mounted: function () {
      this.init();
    },
    methods: {
      init: function () {
        let url = this.octopus.vue.$route.path;
        // MMS 用建筑，需要增加过滤条件
        if (url.indexOf("MMS/Project/Building") > 0) {
          this.octopus.tools.parseCell(this.list.building.data, "ProjectID").searchKey = "=";
          this.octopus.tools.parseCell(this.list.building.data, "CompanyID").searchKey = "=";
          // this.list.building.button = [{class: "success", click: this.create, text: "Create"}]
        } else {
          this.octopus.tools.parseCell(this.list.building.data, "ProjectID").filterValue = this.octopus.passport.project;//默认筛选当前登录的小区
          this.octopus.tools.parseCell(this.item.building.data, "ProjectID").link = [{
            mapping: "CompanyID",
            value: this.octopus.passport.authorization.company
          }];
          // this.octopus.tools.parseCell(this.list.building.data, "ProjectID").show = false;
          // this.octopus.tools.parseCell(this.list.building.data, "CompanyID").show = false;
        }
      },
      create: function (row) {// 创建建筑
        this.item.building.data.value = null;
        this.item.building.control.load();//新增没有数据加载
        this.panel.build.visible = true;

        // this.list.floor
        // this.list.floor.control.load();
      },
      modify: function (row) {// 修改建筑
        this.bulidingID = row.ID;
        this.item.building.data.value = row.ID;
        this.item.building.control.load();
        $(this.list.floor.data.cellData).each(function (index, item) {
          if (item.name == "BuildingID") {
            item.filterKey = "=";
            item.filterValue = row.ID;
          }
        });
        this.panel.build.visible = true;

        this.list.floor.control.load();
        // this.octopus.tools.parseCell(this.list.budget.data, "BuildingID").filterValue = this.bulidingID.toString();
        // this.list.budget.control.load();
      },
      load: function (e) {
        alert(e);
      },
      createFloor: function () {//创建楼层
        this.item.floor.data.value = null;
        this.item.floor.control.load();
        this.panel.floor.visible = true;
      },
      modifyFloor: function (row) {//修改楼层
        this.item.floor.data.value = row.ID;
        this.item.floor.control.load();
        this.panel.floor.visible = true;
      },
      createBudget: function () {//创建Budget
        this.item.budget.data.value = null;
        this.item.budget.control.load();
        this.panel.budget.visible = true;
      },
      modifyBudget: function (row) {//编辑Budget
        this.item.budget.data.value = row.ID;
        this.item.budget.control.load();
        this.panel.budget.visible = true;
      },
      saveBuilding: function (data) {//保存站点
        this.octopus.tips.success(data);
        let params = {
          "type": "Building",
          "id": this.item.building.data.value
        };
        // this.octopus.request.api.post("/ESB/Tools/Transfer/WashRefresh", params)
        // 刷新list
        this.list.building.control.load();
        this.panel.build.visible = false;
      },
      saveFloor: function (data) {//保存楼层
        this.octopus.tips.success(data);
        // let params = {
        //   "type": "Floor",
        //   "id": this.item.floor.data.value
        // };
        // this.octopus.request.api.post("/ESB/Tools/Transfer/WashRefresh", params)
        // 刷新list
        this.list.floor.control.load();
        this.panel.floor.visible = false;
      },
      loadFloor: function () {//加载楼层数据
        let FilterColumn = $.grep(this.item.floor.data.cellData, function (value) {
          return value.name == "BuildingID";//筛选出当前数据列数据
        });
        FilterColumn[0].defaultValue = this.bulidingID.toString();//数据格式转成字符串
      },
      saveBudget: function () {//保存Budget
        // 刷新list
        this.list.budget.control.load();
        this.panel.budget.visible = false;
      },
      loadBudget: function () {////加载Budget
        let FilterColumn = $.grep(this.item.budget.data.cellData, function (value) {
          return value.name == "BuildingID";//筛选出当前数据列数据
        });
        FilterColumn[0].defaultValue = this.bulidingID.toString();//数据格式转成字符串
      },
      output: function (data) {
        this.octopus.tips.success("下载完成。");
      },
      backBuilding: function () {
        this.panel.build.visible = false;
      },
      backFloor: function () {
        this.panel.floor.visible = false;
      }
    },
    props: ["oData"]
  }
</script>

<style scoped></style>
